package servlets.javabeans;

import fr.charlesen.projets.utt.lo09.sessionBeans.ProgrammeBossLocal;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Charles EDOU NZE
 */
@ManagedBean(name = "login")
@RequestScoped
public class loginBeans {

    @EJB
    private ProgrammeBossLocal prog;
    private String username;

    /** Creates a new instance of loginBeans */
    public loginBeans() {
        ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
        HttpServletRequest request = (HttpServletRequest) ec.getRequest();
        setUsername(request.getParameter("username"));
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String doLogin() {
        ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
        HttpServletRequest request = (HttpServletRequest) ec.getRequest();
        String urlRetour = "";
        if (username.equals("florent.retraint@utt.fr") || username.equals("marc.lemercier@utt.fr") || username.equals("alain.ploix@utt.fr")) {
            urlRetour = "tmpl/index.xhtml";
        }
        else if (username.equals("jean_marc.nigro@utt.fr")) {
            urlRetour = "tmpl/indexStages.xhtml";
        }
        else {urlRetour = "tmpl/indexRee.xhtml";}
        //request.setAttribute("username", getUsername());
        return urlRetour;
    }

    public String doLogout() {
        return "../index.xhtml";
    }
}
